package me.caofeng.util;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

/**
 * Copyright © 2017曹峰. All rights reserved.
 *
 * @Prject: mall
 * @Package: me.caofeng.util
 * @Description: 价格转换工具类
 * @Author: 曹峰 blog.caofeng.me
 * @Date: 2017-07-01 0:44
 * @Version: V1.0
 */
public class PriceUtil {
    private static Logger LOGGER = LogManager.getLogger(PriceUtil.class);

    public static int stringToInt(String str) {
        if (CheckUtil.isEmpty(str)){
            return -1;
        }

        int index = str.indexOf(".");
        String intPart = null;
        String doublePart = null;
        if (index > 0){
            intPart = str.substring(0,index);
            doublePart = str.substring(index+1,str.length());
        }else {
            intPart = str;
        }

        int price = -1 ;

        if (intPart != null){
            price = Integer.parseInt(intPart) * 100;
        }
        if (doublePart != null){
            price = price + Integer.parseInt(doublePart) ;
        }

        return price;
    }

    public static String intToString(int origin){
       String price = null;
       price = String.valueOf(origin * 1.0/100);
       return price;
    }
    public static void main(String[] args){
//        String price = "9.90";
//        LOGGER.info(stringToInt(price));
        int price = 10;
        LOGGER.info(intToString(price));
    }
}
